//
//  XXHomePageViewController.m
//  XingXue
//
//  Created by XingXue on 2023.
//  Copyright © 2023 XingXue. All rights reserved.
//

#import "XXHomePageViewController.h"

#import "XXSetUpViewController.h" //设置
#import "XXCADViewController.h" //CAD
#import "XXIncomeTaxCalculationViewController.h" //手电筒
#import "XXCompoundInterestCalculationViewController.h"
#import "XXSubscribeViewController.h"

#import "XXHomeFunctionCell.h"

@interface XXHomePageViewController ()

@end

@implementation XXHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.leftItem.hidden = YES;
    [self setRightItemWithIcon:[UIImage imageNamed:@"home_set"] selector:@selector(gotoSetUpViewController)];
    [self.view bringSubviewToFront:self.navigationBar];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"XXHomeFunctionCell" bundle:nil] forCellReuseIdentifier:@"XXHomeFunctionCell"];
    
    self.tableView.frame = CGRectMake(0,-self.statusBarHeight, kScreenWidth,kScreenHeight + self.statusBarHeight);
    
    if (!kUserManager.userManager.isSubscribe) {
        
        if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstEnter"] boolValue]) {
            XXSubscribeViewController *vc = [XXSubscribeViewController new];
            vc.modalPresentationStyle = UIModalPresentationFullScreen;
            [self.navigationController presentViewController:vc animated:YES completion:nil];
            
        } else {

        }
    }
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;

        subarr = [NSMutableArray arrayWithCapacity:1];
                
        dict =  @{@"class":XXHomeFunctionCell.class,
                  @"height":@([XXHomeFunctionCell getCellFrame:[NSNumber numberWithFloat:kScreenWidth*812/375]]),
                  @"delegate":@YES};
        [subarr addObject:dict];

        [arr addObject:subarr];
        
        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark XXHomeFunctionCellDelegate CAD 个人所得税计算 复利计算

- (void)homeFunctionCell:(XXHomeFunctionCell *)cell button:(UIButton *)sender {
    if (!kUserManager.userManager.isSubscribe) {
        [self gotoSubscribeViewController];
        return;
    }
    
    if (sender.tag == 10) {
        //CAD
        [self gotoCADViewController];
    } else if (sender.tag == 11) {
        //个人所得税计算
        [self gotoIncomeTaxCalculationViewController];
    } else if (sender.tag == 12) {
        //复利计算
        [self gotoCompoundInterestCalculationViewController];
    }
}

#pragma mark - goto

//设置
- (void)gotoSetUpViewController {
    XXSetUpViewController* vc = [XXSetUpViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//CAD
- (void)gotoCADViewController {
    XXCADViewController* vc = [XXCADViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//个人所得税计算
- (void)gotoIncomeTaxCalculationViewController {
    XXIncomeTaxCalculationViewController* vc = [XXIncomeTaxCalculationViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//复利计算
- (void)gotoCompoundInterestCalculationViewController {
    XXCompoundInterestCalculationViewController* vc = [XXCompoundInterestCalculationViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
